//app.js
App({
  onLaunch: function () {
    var openid = wx.getStorageSync("openid");
    console.log("openId:" + openid)
    wx.navigateTo({
      url: '/pages/userCenter/userCenter'
    })
    if (openid) {
      this.globalData.openid = openid
    } else {
      wx.login({
        success: res => {
          if (res.code) {
            wx.request({
              url: "https://api.weixin.qq.com/sns/jscode2session",
              data: {
                appid: "wx0c6ddc854ee29b49",
                secret: "13f635adbfe9ed531941f0448c4f7826",
                js_code: res.code,
                grant_type: "authorization_code"
              },
              success: res => {
                console.log(res)
                if (res.data) {
                  openid = res.data.openid
                  this.globalData.openid = openid
                  wx.setStorageSync("openid", openid)
                  console.log(openid)
                }
              }
            })
          }
        }
      })
    }
  },
  globalData: {
    openid: null,
    userInfo: null
  }
})